//
//  XHBFifthVC.m
//  iOS Object
//
//  Created by 保密 on 2019/6/26.
//  Copyright © 2019年 XiaoHaiBao. All rights reserved.
//

#import "XHBFifthVC.h"
#import "XHBDynamicReplacementAppIconVC.h"

@interface XHBFifthVC ()

@end

@implementation XHBFifthVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"第五页";

    self.datasArray = [NSArray arrayWithObjects:@"动态更换APPicon", nil];
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    switch (indexPath.row) {
        case 0: {
            XHBDynamicReplacementAppIconVC *appIconVC = [[XHBDynamicReplacementAppIconVC alloc] initWithNibName:NSStringFromClass([XHBDynamicReplacementAppIconVC class]) bundle:nil];
            [self.navigationController pushViewController:appIconVC animated:YES];
            break;
        }
        case 1: {
            
            break;
        }
        default:
            break;
    }

}

//peek(预览)
- (nullable UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
{
    //获取按压的cell所在行，[previewingContext sourceView]就是按压的那个视图
    NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell* )[previewingContext sourceView]];
    //调整不被虚化的范围，按压的那个cell不被虚化（轻轻按压时周边会被虚化，再少用力展示预览，再加力跳页至设定界面）
    CGRect rect = CGRectMake(0, 0, self.view.frame.size.width,40);
    previewingContext.sourceRect = rect;
    
    switch (indexPath.row) {
        case 0:
            return [self previewingDynamicReplacementAppIconVC];
        default:
            return nil;
    }
    return nil;
}

- (UIViewController *)previewingDynamicReplacementAppIconVC {
    XHBDynamicReplacementAppIconVC *appIconVC = [[XHBDynamicReplacementAppIconVC alloc] initWithNibName:NSStringFromClass([XHBDynamicReplacementAppIconVC class]) bundle:nil];
    appIconVC.preferredContentSize = CGSizeMake(0.0f,500.0f);
    //返回预览界面
    return appIconVC;
}

@end
